#!/bin/sh
#
#=======================set the variant for setup your program=============
PROG=ups_manager
UNINSTALL_DIR=`pwd`
PROGRAM_DIR=/etc/ups_manager
 uid=`id | sed 's/^uid=\([0-9][0-9]*\).*$/\1/'`
 if [ $uid -ne 0 ]; then
    echo "Not logged in as root."
    exit 1
 fi

#----------------------------------------------------------------------------------e
#	=========================chen add this =====================================/
#	Start delete  file
#	==============================================================/
{
		ps -A |awk '{if (index($0, "ups_manager") != 0 || index($0, "ups_monitor") != 0 \
			|| index($0, "ups_config") != 0 || index($0, "ups_status") != 0) \
			print($1); }' |xargs kill 2>/dev/null
}


#	=========================vicly add this =====================================/
#	Operation after copy file finished
#	Add the IPPMonitor star command into the rc.local ,so it will be  started when the system startup.
#	==============================================================/
{
	STARTUP=/etc/rc
	echo ""
	echo "Remove entries in $STARTUP ...."
	rm $UNINSTALL_DIR/startup.tmp* 2> /dev/null
	sed 's/#\/etc\/RichComm/# \/etc\/ups_manager/' $STARTUP > $UNINSTALL_DIR/startup.tmp1
	difference=""
	difference=`grep /etc/ups_manager $STARTUP | awk 'index($1,"if")==0 && index($1,"#")==0 {print $1}' | head -1`
	echo "the difference is :$difference"
	if [ $difference ]; then
		cat $UNINSTALL_DIR/startup.tmp1 | awk '{if ((index($0,"/etc/ups_manager/ups_manager &") != 0 || index($0, "ups_manager start") != 0 \
			|| index($0,"# BEGIN: Startup for UPS Manager[ups_manager]") != 0 || index($0,"# END: Startup for UPS Manager[ups_manager]") != 0) \
			&& $1 != "if") ; else print}' > $UNINSTALL_DIR/startup.tmp2
		cp $UNINSTALL_DIR/startup.tmp2 $STARTUP
	fi
	rm $UNINSTALL_DIR/startup.tmp* 2> /dev/null
	echo "Remove $PROGRAM_DIR"
	rm -rf $PROGRAM_DIR
	echo "OK"
}


